<template>
	<view>
		<view
			class="d-flex flex-r ali-i-c just-c b-box"
			style="padding: 34rpx ;border-bottom: 2rpx solid #EEEEEE;"
		>
			<text
				class="pf-sc fw-400"
				style="font-size: 30rpx;color: rgba(0,0,0,0.9000);margin-right: 24rpx;"
			>
				姓名
			</text>
			<u-input
				type="text"
				v-model="name"
				border="none"
				placeholder="请输入您的姓名"
				disabledColor="#ffffff"
				placeholderStyle="color:#999999;fontWeight:400;fontsize:30px;fontfamily:PingFang SC-Regular, PingFang SC"
				:customStyle="{ color: 'rgba(0,0,0,0.9000)', font: '400 30rpx PingFang SC' }"
			></u-input>
		</view>

		<view
			class="d-flex flex-r ali-i-c just-c b-box"
			style="padding: 34rpx 32rpx;border-bottom: 2rpx solid #EEEEEE;"
			@click="showSex = true"
		>
			<text
				class="pf-sc fw-400"
				style="font-size: 30rpx;color: rgba(0,0,0,0.9000);margin-right: 24rpx;"
			>
				身份
			</text>
			<u-input
				type="text"
				border="none"
				:placeholder="value"
				v-module="value"
				disabledColor="#ffffff"
				disabled
				disableDefaultPadding
				placeholderStyle="color:#999999;fontWeight:400;fontsize:30px;fontfamily:PingFang SC-Regular, PingFang SC"
				:customStyle="{ color: 'rgba(0,0,0,0.9000)', font: '400 30rpx PingFang SC' }"
			></u-input>
		</view>
		<u-action-sheet
			:show="showSex"
			:actions="actions"
			title="请选择您的身份"
			@close="showSex = false"
			@select="sexSelect"
		></u-action-sheet>

		<view class="d-flex flex-r ali-i-c  b-box" style="padding: 34rpx 32rpx;">
			<view class="d-flex flex-c ali-i-s just-s " style="width: 166rpx;">
				<text class="pf-sc fw-400" style="font-size: 30rpx;color: rgba(0,0,0,0.9000);">军官证</text>
				<text class="pf-sc fw-400" style="font-size: 30rpx;color: rgba(0,0,0,0.9000);">警官证</text>
			</view>
			<view @click="uploadimg">
				<image
					v-if="idoimage"
					:src="idoimage"
					mode="widthFix"
					style="width: 126rpx;height: 126rpx;"
				></image>
				<image
					:src="require('../../../static/add.png')"
					mode="widthFix"
					style="width: 126rpx;height: 126rpx;"
				></image>
			</view>
		</view>
		<button class="button" @click="submit">提交</button>
	</view>
</template>

<script>
import { shenqing } from '@/common/api.js';
export default {
	data() {
		return {
			name: '',
			value: '请选择您的身份',
			showSex: false,
			idoimage: '',
			actions: [
				{
					name: '军人'
				},
				{
					name: '军属'
				}
			]
		};
	},
	methods: {
		sexSelect(e) {
			this.value = e.name;
			console.log(this.value);
		},
		//上传图片
		uploadimg() {
			//修改头像
			uni.chooseImage({
				success: chooseImageRes => {
					const tempFilePaths = chooseImageRes.tempFilePaths;
					const uploadTask = uni.uploadFile({
						url: 'https://www.chejingjing.cn/api/index/uploadimg',
						filePath: tempFilePaths[0],
						name: 'photo',
						formData: {
							photo: tempFilePaths[0]
						},
						success: res => {
							res = JSON.parse(res.data).data.url;
							console.log(res, '图片');
							this.idoimage = res;
						}
					});
				}
			});
		},
		submit() {
			if (this.name == '') {
				uni.showToast({
					title: '请输入您的姓名',
					icon: 'none'
				});
				return;
			}
			if (this.value == '请选择您的身份') {
				uni.showToast({
					title: '请选择您的身份',
					icon: 'none'
				});
				return;
			}
			if (this.idoimage == '') {
				uni.showToast({
					title: '请上传您的证件照片',
					icon: 'none'
				});
				return;
			}
			let params = {
				token: uni.getStorageSync('usertoken'),
				shenfen: this.value,
				images: this.idoimage,
				type: 2
			};

			shenqing(params).then(res => {
				if (res.data.code == 1) {
					uni.showToast({
						title: '提交成功',
						icon: 'success'
					});
					setTimeout(() => {
						uni.switchTab({
							url: '/pages/UserHomePage/UserHomePage'
						});
					}, 2000);
				} else {
					uni.showToast({
						title: res.data.msg,
						icon: 'none'
					});
				}
			});
		}
	}
};
</script>

<style lang="scss">
.u-input__content__field-wrapper__field {
	padding: 0;
}
.button {
	width: 670rpx;
	height: 88rpx;
	line-height: 88rpx;
	margin: 0 auto;
	text-align: center;
	border-radius: 88rpx;
	background: linear-gradient(180deg, #4885c5 0%, #3b52a6 100%);
	opacity: 1;
	font-size: 32rpx;
	font-family: PingFang SC-Medium, PingFang SC;
	font-weight: 500;
	color: #ffffff;
	margin-top: 92rpx;
}
</style>
